﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HostAgentCore;

namespace WindowsPhoneHostAgent
{
    public class WindowsPhoneApplicationDefinition
    {
        public string ApplicationId { get; set; }
        public string ApplicationName { get; set; }
        public string ApplicationPackagePath { get; set; }
        public string ApplicationIconPath { get; set; }

        public Guid ProductGuid { get { return SafeParseGuid(ApplicationId); } }
        public Guid InstanceGuid { get { return SafeParseGuid(ApplicationId); } }

        public WindowsPhoneApplicationDefinition()
        {
        }

        public WindowsPhoneApplicationDefinition(ApplicationDefinition applicationDefinition)
        {
            ApplicationId = applicationDefinition.Fields["ApplicationId"];
            ApplicationName = applicationDefinition.Fields["ApplicationName"];
            ApplicationPackagePath = applicationDefinition.Fields["ApplicationPackagePath"];
            ApplicationIconPath = applicationDefinition.Fields["ApplicationIconPath"];

        }

        private static Guid SafeParseGuid(string input)
        {
            Guid toReturn;
            if (Guid.TryParse(input, out toReturn))
                return toReturn;

            return Guid.Empty;
        }
    }
}
